/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Home.java
 *
 * Created on May 7, 2011, 11:19:47 AM
 */

package gui;

import classes.Bet;
import classes.userBet;
import client.Request;
import classes.User;
import java.awt.Color;
import java.awt.Font;
import java.awt.Paint;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.*;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author mayakreidieh
 */
public class BettingPanel extends javax.swing.JPanel {

    Request Client;
    User User;
    Bet[] allBets;
    /** Creates new form Home */
    public BettingPanel(Request client, User user ) {

        Client = client;
        User = user;
        initComponents();
        String[] tokens = null;

  //      tokens = Client.getBets();
  //    createTable(tokens);

        int i;
        jSeparator11.setVisible(false);
        jSeparator2.setVisible(false);
        jSeparator4.setVisible(false);
        jSeparator5.setVisible(false);
        jSeparator7.setVisible(false);
        jSeparator9.setVisible(false);

        JFreeChart chart = createGraph();
        ChartPanel chPanel = new ChartPanel(chart); //creating the chart panel, which extends JPanel
        
        chPanel.setMouseWheelEnabled(true);
        pantest.add(chPanel); //add the chart viewer to the JPanel

    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator4 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator7 = new javax.swing.JSeparator();
        jSeparator9 = new javax.swing.JSeparator();
        jSeparator11 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        ref = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();
        pantest = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jsep2 = new javax.swing.JSeparator();
        loc = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        date = new javax.swing.JLabel();
        title = new javax.swing.JLabel();
        jLabel11 = new TransparentButton(1);
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jsep1 = new javax.swing.JSeparator();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel23 = new TransparentButton(0.85f);
        jLabel10 = new TransparentButton(0.75f);

        setBackground(new java.awt.Color(0, 51, 204));
        setOpaque(false);
        setLayout(null);

        jLabel2.setFont(new java.awt.Font("Helvetica CY", 1, 36)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 153, 255));
        jLabel2.setText("Ongoing Bets");
        add(jLabel2);
        jLabel2.setBounds(860, 30, 240, 40);

        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("and bet!");
        add(jLabel5);
        jLabel5.setBounds(860, 100, 270, 30);

        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Select a game to view game info and statistics,");
        add(jLabel7);
        jLabel7.setBounds(860, 80, 300, 30);

        ref.setFont(new java.awt.Font("Helvetica", 0, 14));
        ref.setText("Referee :");
        add(ref);
        ref.setBounds(590, 620, 130, 30);

        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Team 1", "Team 2", "Team 1 wins", "Draw", "Team 2 wins"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(table);

        add(jScrollPane2);
        jScrollPane2.setBounds(260, 70, 450, 270);

        pantest.setLayout(new javax.swing.BoxLayout(pantest, javax.swing.BoxLayout.LINE_AXIS));
        add(pantest);
        pantest.setBounds(280, 480, 290, 210);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uefa/dollar_gold.png"))); // NOI18N
        jLabel1.setText("jLabel1");
        add(jLabel1);
        jLabel1.setBounds(1120, 360, 30, 30);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/uefa/chart_info.png"))); // NOI18N
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });
        add(jLabel3);
        jLabel3.setBounds(670, 390, 40, 30);

        jLabel8.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel8.setText("Date");
        add(jLabel8);
        jLabel8.setBounds(590, 500, 130, 30);

        jLabel4.setFont(new java.awt.Font("Helvetica Neue", 1, 13));
        jLabel4.setText("Get game info");
        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel4MouseClicked(evt);
            }
        });
        add(jLabel4);
        jLabel4.setBounds(580, 400, 90, 16);
        add(jsep2);
        jsep2.setBounds(260, 370, 450, 12);

        loc.setFont(new java.awt.Font("Helvetica", 0, 14));
        loc.setText("beirut");
        add(loc);
        loc.setBounds(590, 570, 130, 30);

        jLabel9.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel9.setText("Referee");
        add(jLabel9);
        jLabel9.setBounds(590, 600, 130, 30);

        jLabel12.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel12.setText("Location");
        add(jLabel12);
        jLabel12.setBounds(590, 550, 130, 30);

        date.setFont(new java.awt.Font("Helvetica", 0, 14));
        date.setText("may 10 2011");
        add(date);
        date.setBounds(590, 520, 130, 30);

        title.setFont(new java.awt.Font("Helvetica", 0, 17));
        title.setText("title vs title");
        add(title);
        title.setBounds(280, 440, 380, 18);

        jLabel11.setBackground(new java.awt.Color(255, 255, 255));
        jLabel11.setOpaque(true);
        add(jLabel11);
        jLabel11.setBounds(220, 40, 540, 1330);

        jPanel1.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.setOpaque(false);
        jPanel1.setLayout(null);

        jLabel13.setFont(new java.awt.Font("Helvetica", 0, 14));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Win/Draw/Win");
        jPanel1.add(jLabel13);
        jLabel13.setBounds(120, 50, 100, 16);

        jLabel14.setFont(new java.awt.Font("Helvetica", 0, 14));
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("TeamA vs TeamB");
        jPanel1.add(jLabel14);
        jLabel14.setBounds(120, 70, 130, 16);

        jLabel15.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText(" Market");
        jPanel1.add(jLabel15);
        jLabel15.setBounds(60, 50, 50, 15);

        jLabel16.setFont(new java.awt.Font("Helvetica", 0, 14));
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setText("MM DD YYYY");
        jPanel1.add(jLabel16);
        jLabel16.setBounds(120, 90, 110, 16);

        jLabel17.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel17.setForeground(new java.awt.Color(255, 255, 255));
        jLabel17.setText("Event");
        jPanel1.add(jLabel17);
        jLabel17.setBounds(70, 70, 39, 15);

        jLabel18.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel18.setForeground(new java.awt.Color(255, 255, 255));
        jLabel18.setText(" Bid Ammount");
        jPanel1.add(jLabel18);
        jLabel18.setBounds(10, 150, 100, 20);

        jLabel19.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel19.setForeground(new java.awt.Color(255, 255, 255));
        jLabel19.setText("Date and Time");
        jPanel1.add(jLabel19);
        jLabel19.setBounds(10, 90, 100, 15);

        jLabel20.setFont(new java.awt.Font("Helvetica", 1, 14));
        jLabel20.setForeground(new java.awt.Color(255, 255, 255));
        jLabel20.setText(" Type");
        jPanel1.add(jLabel20);
        jLabel20.setBounds(70, 130, 40, 15);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel1.add(jComboBox1);
        jComboBox1.setBounds(120, 120, 160, 27);

        jTextField1.setText("($)");
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField1);
        jTextField1.setBounds(120, 150, 160, 28);
        jPanel1.add(jSeparator2);
        jSeparator2.setBounds(10, 10, 0, 12);

        jsep1.setForeground(new java.awt.Color(102, 204, 255));
        jPanel1.add(jsep1);
        jsep1.setBounds(0, 0, 330, 10);

        add(jPanel1);
        jPanel1.setBounds(850, 130, 310, 210);

        jLabel21.setBackground(new java.awt.Color(254, 209, 232));
        jLabel21.setAutoscrolls(true);
        add(jLabel21);
        jLabel21.setBounds(940, 270, 200, 70);

        jLabel22.setBackground(new java.awt.Color(153, 255, 153));
        jLabel22.setFont(new java.awt.Font("Helvetica", 1, 13));
        jLabel22.setForeground(new java.awt.Color(255, 204, 102));
        jLabel22.setText("Make me money!");
        jLabel22.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel22MouseClicked(evt);
            }
        });
        add(jLabel22);
        jLabel22.setBounds(1010, 370, 110, 16);

        jLabel6.setText("jLabel6");
        add(jLabel6);
        jLabel6.setBounds(320, 1450, 45, 16);

        jLabel23.setBackground(new java.awt.Color(0, 0, 0));
        jLabel23.setText("jLabel10");
        jLabel23.setOpaque(true);
        add(jLabel23);
        jLabel23.setBounds(180, 10, 620, 1400);

        jLabel10.setBackground(new java.awt.Color(0, 0, 0));
        jLabel10.setText("jLabel10");
        jLabel10.setOpaque(true);
        add(jLabel10);
        jLabel10.setBounds(830, 10, 340, 1400);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked

        getInfo();
    }//GEN-LAST:event_jLabel4MouseClicked

    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked

        getInfo();
    }//GEN-LAST:event_jLabel3MouseClicked

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jLabel22MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel22MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel22MouseClicked

    public void getInfo(){

        //table.ge

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel date;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JSeparator jsep1;
    private javax.swing.JSeparator jsep2;
    private javax.swing.JLabel loc;
    private javax.swing.JPanel pantest;
    private javax.swing.JLabel ref;
    private javax.swing.JTable table;
    private javax.swing.JLabel title;
    // End of variables declaration//GEN-END:variables


    /* Fills the game panels with the games received from the database
     */
    public void createTable(String[] tokens){

        System.out.println("Creating betting table");
    /*
        Bet[] allBets;
       // Client.getAllBets(allBets); all function get all bets

        String[] col = {"Game", "Win", "Draw", "lose"};

        tokens = new String[1][6];
        for (i=0;i<6;i++)
            tokens[0][i] = "fad";

        DefaultTableModel model = new DefaultTableModel(null,col);
        for (i=0;i<tokens.length/6; i++)
        //model.insertRow(i, new Object[] {tokens[0+6*i], tokens[1+6*i], tokens[2+6*i],tokens[3+6*i], tokens[4+6*i], tokens[5+6*i]});
        table.setModel(model);



*/
    }

    public JFreeChart createGraph(){


        int i = table.getSelectedRowCount();
// where fields: 1 = id, 2 = home team, 3 = away team, 4 = location, 5 = startdate, 7 = referee

        //Client.getGames(1, allBets[i].gameID, );
     DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Win", 23.3);
        dataset.setValue("Draw", 56.5);
        dataset.setValue("lose", 43.3);

        JFreeChart chart = ChartFactory.createPieChart3D("", dataset, false, false, false);
        chart.setBackgroundPaint(new Color (222, 222, 225));
        chart.setBorderPaint(Color.white);
        PiePlot3D plot3 = (PiePlot3D) chart.getPlot();
        plot3.setForegroundAlpha(0.7f);
        plot3.setCircular(true);
        plot3.setBackgroundPaint(Color.white);
        plot3.setBaseSectionPaint(Color.white);
        plot3.setLabelBackgroundPaint(Color.white);
        plot3.setLabelFont(new Font("Helvetica", Font.PLAIN, 12));

      return chart;
    }
}


